package kr.totalcall.constant
{
	import kr.totalcall.business.CallLinkerClient;
	import kr.totalcall.view.receive.CallPassReceiveController;
	
	import mx.collections.XMLListCollection;
	import mx.core.FlexGlobals;

	/**
	 * 작업 기록
	 * 2012. 6. 12. / 이규광 / 최초 작성.
	 */
	/**
	 * 내용.
	 * TotalCall Application 기본정보
	 * @productversion Flex 4.5
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 10.2
	 * @author 이규광.
	 */
	public class TotalCallGlobals
	{
		
		
		// main
		private static var _main:TotalCall;
		public static function get main():TotalCall{
			if(!_main){
				_main = FlexGlobals.topLevelApplication as TotalCall;
			}
			return _main;
		}
		
		
		
		public static function get isDebug():Boolean{
			return main.bDebug;
		}
		
		
		//===============================================================================================
		//  쿠키성 데이터 // shared object - getLocal("TotalCall")
		//===============================================================================================
		public static function get cookie():Object{
			return main.cookie.data;
		}
		
		public static function setCookieData(key:String, data:Object):void{
			cookie[key] = data;
			main.cookie.flush();
		}
		
		
		//===============================================================================================
		//  콜그룹 관련 정보
		//===============================================================================================
		public static var callGroupNum:String ;
		
		// 현 지사의 콜그룹 list...
		[Bindable] public static var callGroupXC:XMLListCollection;
		
		// 지사 이름
		private static var _branchName:String;
		public static function get branchName():String{
			/*if(!_branchName || _branchName != main.dropBranch.selectedItem.name){
			_branchName = main.dropBranch.selectedItem.name;
			}*/
			
			if(main.callGroupTabbar && main.callGroupTabbar.selectedItem){
				if(callGroupAll){
					_branchName = userBranchName;
				}else{
					_branchName = main.callGroupTabbar.selectedItem.name;
				}
			}else{
				_branchName = userBranchName;
			}
			return _branchName;
		}
		
		// 지사 번호
		private static var _branchNum:String;
		public static function get branchNum():String{
			/*if(!_branchNum || _branchNum != main.callGroupTabbar.selectedItem.num){
			_branchNum = main.callGroupTabbar.selectedItem.num;
			}*/
			
			if(main.callGroupTabbar && main.callGroupTabbar.selectedItem){
				if(callGroupAll){
					_branchNum = userBranchNum;
				}else{
					_branchNum = main.callGroupTabbar.selectedItem.num;
				}
			}else{
				_branchNum = userBranchNum;
			}
			return _branchNum;
		}
		
		// 콜그룹 "전체"를 클릭했는지..
		public static var callGroupAll:Boolean = false;
		
		public static function get callGroupBranchNumArr():Array{
			var arr : Array = [];
			for(var i : int = 0 ; i < main.callGroupTabbar.dataProvider.length; i++){
				if(main.callGroupTabbar.dataProvider[i].num.toString() == "0") continue;
				arr.push(main.callGroupTabbar.dataProvider[i].num.toString());
			}
			return arr;
		}
		public static function get callGroupBranchNumArrStr():String{
			var arr : Array = [];
			for(var i : int = 0 ; i < main.callGroupTabbar.dataProvider.length; i++){
				if(main.callGroupTabbar.dataProvider[i].num == 0) continue;
				arr.push(main.callGroupTabbar.dataProvider[i].num);
			}
			return "(" + arr.toString() + ")";
		}
		
		
		
		//===============================================================================================
		//  로그인 유저 정보
		//===============================================================================================
		// 로그인 한 유저의 지사 번호
		[Bindable] public static var userBranchNum:String = "";
		
		// 로그인 한 유저의 지사 이름
		[Bindable] public static var userBranchName:String = "";
		
		// 지사의 그룹 번호
		public static var userBranchGroupNum:String = "";
		
		// 지사의 그룹오너의 지사번호
		public static var userBranchGroupOwnerNum:String = "";
		
		// 사용자 이름
		private static var _userName:String;
		public static function get userName():String{
			if(!_userName || _userName != main.labelName.text){
				_userName = main.labelName.text;
			}
			return _userName;
		}
		
		// 사용자 ID
		public static var userId:String = "#";
		/*
		// 사용자 ID
		private static var _userId:String;
		public static function get userId():String{
			if(!_userId || _userId != main.inputID.text){
				_userId = main.inputID.text;
			}
			return _userId;
		}
		*/
		
		public static var keyphoneNum:String = "212";
		
		
		
		//===============================================================================================
		//  로그인 유저 권한 관련
		//===============================================================================================
		
		/**
		 * 최고 지사 그룹인지 (통합콜인지)
		 */
		[Bindable] public static var adminBranch:Boolean = false;
		
		/**
		 * 지사관리화면에서 지사그룹 List를 볼 수 있는지
		 */
		[Bindable] public static var showBranchGroupList:Boolean = false;
		
		/**
		 * 지사관리화면에서 지사 List를 볼 수 있는지
		 */
		[Bindable] public static var showBranchList:Boolean = false;
		
		/**
		 * 요금표Tab을 볼 수 있는지
		 */
		[Bindable] public static var showFarePolicy:Boolean = false;
		
		/**
		 * 요금표Tab을 볼 수 있는지
		 */
		[Bindable] public static var farePolicyEdiable:Boolean = false;
		
		
		
		
		//===============================================================================================
		//  보안 관련
		//===============================================================================================
		
		[Bindable] public static var strSecure:String = "1029";
		/*
		// 보안키 (서버에서 데이터를 가지고 올때 사용되는 것 같음)
		private static var _strSecure:String;
		public static function get strSecure():String{
			if(!_strSecure || _strSecure != main.strSecure){
				_strSecure = main.strSecure;
			}
			return _strSecure;
		}
		*/
		
		
		
		//===============================================================================================
		//  할증 관련
		//===============================================================================================
		/**
		 * 야간 할증이 붙는지
		 */
		public static function get chkExtraNight():Boolean{
			var rtn:Boolean = false;
			if(main && main.receive && main.receive.chkExtraNight){
				rtn = main.receive.chkExtraNight.selected ;
			}
			return rtn;
		}
		
		/**
		 * 우천 할증이 붙는지
		 */
		public static function get chkExtraRain():Boolean{
			var rtn:Boolean = false;
			if(main && main.receive && main.receive.chkExtraRain){
				rtn = main.receive.chkExtraRain.selected ;
			}
			return rtn;
		}
		
		/**
		 * 휴일 할증이 붙는지
		 */
		public static function get chkExtraHoliday():Boolean{
			var rtn:Boolean = false;
			if(main && main.receive && main.receive.chkExtraHoliday){
				rtn = main.receive.chkExtraHoliday.selected ;
			}
			return rtn;
		}
		
		
		
		//===============================================================================================
		//  지사옵션 관련
		//===============================================================================================
		/**
		 * 신용도 적용안함 - 기본 세팅
		 */
		public static var defaultChkNoCredit : Boolean = false;
		
		
		
		//===============================================================================================
		//  콜패스 관련
		//===============================================================================================
		/**
		 * call pass 관련
		 */
		public static var callpassController:CallPassReceiveController = new CallPassReceiveController();
		
		
		/**
		 * 메인의 콜패스알림이 켜져있는지 리턴
		 */
		public static function get chkCallPassNotice():Boolean{
			var rtn:Boolean = false;
			if(main && main.chkReceivedCallPass){
				rtn = main.chkReceivedCallPass.selected ;
			}
			return rtn;
		}
		
		
		
		
		
		//===============================================================================================
		//  지사목록 관련
		//===============================================================================================
		/**
		 * 지사 목록 XML
		 */
		[Bindable] public static var branchTreeData:XML;
		
		/**
		 * 지사 목록 XMLListCollection
		 */
		[Bindable] public static var branchTreeXMLListCol:XMLListCollection;
		
		
		
		
		//===============================================================================================
		//  keyphone 관련
		//===============================================================================================
		private static var _callLinker:CallLinkerClient = null;
		
		public static function get callLinker():CallLinkerClient{
			if(!_callLinker){
				_callLinker = new CallLinkerClient();
			}
			return _callLinker;
		}
		
		public static function initCallLinker(ip:String, port:int=5882, isConnect:Boolean = true):void{
			callLinker.initSocket(ip, port, isConnect);
		}
		
		
		/**
		 * 자동으로 접수창을 띄울것인지..
		 *
		public static function autoPopupReceive():Boolean{
			if(!main || !main.receive || !main.receive.checkBoxAutoPopupReceiveForm) 
				return false;
			
			return main.receive.checkBoxAutoPopupReceiveForm.selected;
		}*/
		
		
		
		
		
		
		
		//===============================================================================================
		//  메세지 관련
		//===============================================================================================
		
		/**
		 * 메세지를 채팅처럼 자동수신할 것 인지
		 */
		public static function get chkMessage():Boolean{
			var rtn:Boolean = false;
			
			if(TotalCall(FlexGlobals.topLevelApplication).chkMessage){
				rtn = TotalCall(FlexGlobals.topLevelApplication).chkMessage.selected ;
			}
			return rtn;
		}
		
		
		
		/**
		 * 생성자
		 */
		public function TotalCallGlobals()
		{
		}
	}
}